package com.ck.ips.controller;

import com.ck.common.model.OperationResult;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.constant.RequestConstant;
import com.ck.ips.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
* @Description: 用户个人信息controller
* @Author: hf
* @Date:    2019/5/6 10:54
* @Version: 1.0
*/
@LoginRequired
@RestController
@RequestMapping("userinfo")
public class UserInfoController extends BaseController{
    private static Logger logger = LoggerFactory.getLogger(UserInfoController.class);
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 获取用户个人信息
     */
    @PostMapping("/basic")
    public Object getUserInfo(){
        return userInfoService.getUserInfo();
    }

    /**
     * 修改用户个人基础信息
     */
    @PostMapping("/modify")
    public Object updateUserInfo(String avatar, String nickName, String gender, String mobilePhone){
        return userInfoService.updateUserInfo(avatar,nickName,gender,mobilePhone);
    }

    /**
     * 修改密码
     */
    @PostMapping("/changepwd")
    public Object changePwd(String oldPwd, String newPwd, HttpServletRequest request){
        OperationResult operationResult = userInfoService.changePwd(oldPwd, newPwd);
        if ( operationResult.isSucess() ) {
            logOut();
        }
        request.getSession().removeAttribute(RequestConstant.SESSION_KEY_USER);
        return operationResult;
    }


}
